package com.yz.android_baozou.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yz.android_baozou.R;
import com.yz.android_baozou.activity.MainPageDetailActivity;
import com.yz.android_baozou.bean.RankBean;
import com.yz.android_baozou.helper.RecyclerViewAdapterHelper;

import java.util.List;

/**
 * Created by Administrator on 2016/11/3.
 */

public class Search_RecyclerAdapter extends RecyclerViewAdapterHelper<RankBean.DataBean>{
    private RecyclerView recyclerViewRankMain;

    public Search_RecyclerAdapter(Context context, List<RankBean.DataBean> list, RecyclerView _recyclerViewRankMain) {
        super(context, list);
        this.recyclerViewRankMain = _recyclerViewRankMain;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_search_main, parent, false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = recyclerViewRankMain.getChildAdapterPosition(v);
                String url=list.get(position).getShare_url();
                Bundle bundle=new Bundle();
                bundle.putString("url",url);
                Intent intent=new Intent(context, MainPageDetailActivity.class);
                intent.putExtra("url",bundle);
                context.startActivity(intent);
            }
        });
        return new MyViewHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyViewHolder) {
            ((MyViewHolder) holder).textView_Content_item_search.setText(list.get(position).getTitle());
            ((MyViewHolder) holder).textView_author_item_search.setText(list.get(position).getAuthor_name());
            ((MyViewHolder) holder).textView_type_item_search.setText(list.get(position).getSection_name());
            Glide.with(context).load(list.get(position).getThumbnail()).into(((MyViewHolder) holder).imageView_show_item_search);
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView_show_item_search;
        private TextView textView_Content_item_search;
        private TextView textView_author_item_search;
        private TextView textView_type_item_search;

        public MyViewHolder(View itemView) {
            super(itemView);
            imageView_show_item_search = (ImageView) itemView.findViewById(R.id.imageView_show_item_search);
            textView_Content_item_search = (TextView) itemView.findViewById(R.id.textView_Content_item_search);
            textView_author_item_search = (TextView) itemView.findViewById(R.id.textView_author_item_search);
            textView_type_item_search = (TextView) itemView.findViewById(R.id.textView_type_item_search);
        }
    }
}
